//
//  WYDevHelper.h
//  WYDevHelper
//
//  Created by longtu on 15/5/19.
//  Copyright (c) 2015年 longtu. All rights reserved.
//

#ifndef test_WYConfig_h
#define test_WYConfig_h

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

/* 比NSLog更高级的DLog */
#ifdef DEBUG
#   define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#   define DLog(...)
#endif

/* Statusbar */
#define IOS7 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
#define IOS7_STATUS_BAR_HEGHT (IOS7 ? 20.0f : 0.0f)

/* EGB 色值 */
#define RGBA(R/*红*/, G/*绿*/, B/*蓝*/, A/*透明*/) [UIColor colorWithRed:R/255.f green:G/255.f blue:B/255.f alpha:A]

/* @name 字体相关宏 */
#define FontWithSize(Size) [UIFont systemFontOfSize:Size]
#define BoldFontWithSize(Size) [UIFont boldSystemFontOfSize:Size]

/* @name 生成图片相关 */
#define ImageWithName(Name) ([UIImage imageNamed:Name])
#define BigImageWithName(Name) ([UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:Name ofType:nil]])


/* System Versioning Preprocessor Macros */
// 系统版本等于
#define SYSTEM_VERSION_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
// 系统版本高于
#define SYSTEM_VERSION_GREATER_THAN(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
// 系统版本大于或等于
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
// 系统版本低于
#define SYSTEM_VERSION_LESS_THAN(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
// 系统版本小于或等于
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)


#pragma mark - 加载进度
@class WYProgressHUD;
@interface WYProgressHUD : UIView
// 显示加载进度
+ (void) showLoading;
// 移除加载提示
+ (void) hiddenLoading;
// 显示提示文字
+ (void) showMessage:(NSString *)string hideTime:(float)hideTime;
@end



#pragma mark - 文件管理类
@class WYFilePathHelper;
@interface WYFilePathHelper : NSObject
// DocumentDirectory
+ (NSString *) fileDocumentDirectory;
// Caches
+ (NSString *) fileCachesDirectory;
// LibraryDirectory
+ (NSString *) fileLibraryDirectory;

/**
 * 缓存文件和清除缓存
 */
// 单个文件的大小
+ (float ) fileSizeAtPath:(NSString*) filePath;
// 遍历文件夹获得文件夹大小，返回多少M
+ (float ) folderSizeAtPath:(NSString*) folderPath;
// 传入数字返回文件大小的字符串
+ (NSString *) transferNumberToString:(float )number;
// 传入数字返回时间的字符串
+ (NSString *) formatTimeByNumber:(float)time;
// 是否存在指定文件
+ (BOOL) isExistFileAtPath:(NSString *)path;
// 删除path文件
+ (BOOL) removeFileAtPath:(NSString *)path;
/**
 *    @param     sourcePath     Resource文件路径
 *    @param     toPath     把文件拷贝到XXX文件夹
 *    @return    BOOL
 */
+ (BOOL) copyMissingFile:(NSString *)sourcePath toPath:(NSString *)toPath;
/**
 *    @brief    创建文件夹
 *    @param     createDir     创建文件夹路径
 */
+ (void) createFolder:(NSString *)createDir;
@end



#pragma mark - image 图片的操作
@interface UIImage (WYimage)
// BASE64编码转图片
+ (UIImage *) stringToImage:(NSString *)string;
// 等比率缩放
+ (UIImage *) scaleImage:(UIImage *)image toScale:(float)scaleSize;
// 自定长宽
+ (UIImage *) reSizeImage:(UIImage *)image toSize:(CGSize)reSize;
// 设置图片透明度
+ (UIImage *) image:(UIImage*)image imageAlpha:(CGFloat)alpha;
// 合并2张图片
+ (UIImage *) addImage:(UIImage *)image1 toImage:(UIImage *)image2;
@end



#pragma mark - 网络请求
typedef NS_ENUM(NSInteger, WYNetworkStatus){
    WYNotReachable = 0,
    WYReachableViaWiFi,
    WYReachableViaWWAN,
    WYReachableVia3G,
    WYReachableVia2G
};
@class WYHttpHelper;
@protocol WYHttpHelperDelegate;
// 返回数据
typedef void (^WYHttpRequestBlock)(id data);

// 网络请求错误信息
typedef void(^WYHttpErrorBlock)(NSError *error);

@interface WYHttpHelper : NSObject
// 网络请求唯一标示
@property(copy, nonatomic) NSString  *indifier;
// 第一次打开时判断网络状态
+ (WYNetworkStatus ) connectedToNetwork;

@property (strong, nonatomic) WYHttpRequestBlock netRequestBlock;

@property (strong, nonatomic) WYHttpErrorBlock httpErrorBlock;

/* block */
+ (void ) getRequestWithURL:(NSString *)urlStr
         andNetRequestBlock:(WYHttpRequestBlock )block errorBlock:(WYHttpErrorBlock )errorBlock;
+ (void ) postRequestWithURL:(NSString *)urlStr
                      andDic:(NSDictionary *)dic
          andNetRequestBlock:(WYHttpRequestBlock )block errorBlock:(WYHttpErrorBlock )errorBlock;
+ (void ) postRequestWithURL:(NSString *)urlStr
                     andBody:(NSString *)body
          andNetRequestBlock:(WYHttpRequestBlock )block errorBlock:(WYHttpErrorBlock )errorBlock;

/* delegate */
@property(assign, nonatomic) id<WYHttpHelperDelegate> delegate;
// get 请求
- (void ) sentRequest:(NSString *)temp_url_str;
- (id ) initWithDelegate:(id<WYHttpHelperDelegate>)delegate;
// POST 请求，传入字符串
- (void ) sentPostRequest:(NSString *)urlstr andBody:(NSString *)body;
// POST 请求，传入字典
- (void ) sentPostRequest:(NSString *)urlstr andDic:(NSDictionary *)dic;
// 停止网络请求
- (void ) cancelRequest;
@end

@protocol WYHttpHelperDelegate <NSObject>
// 网络请求成功回调
- (void ) getdata:(id )data andIndifier:(NSString *) indefier requestSuccess:(BOOL)sucess;
@end



#pragma mark - 色值转换RGB
@interface UIColor (WYHexString)
// 16进制转RGB
+ (UIColor *) colorWithHexString:(NSString *)colorString;
+ (UIColor *) colorWithHexString:(NSString *)colorString alpha:(CGFloat)a;
// 颜色转字符串
+ (NSString *) changeUIColorToRGB:(UIColor *)color;
// 十进制转十六进制
+ (NSString *) ToHex:(int)tmpid;
@end


#endif


